<?php
namespace EasySwoole\EasySwoole;


use EasySwoole\EasySwoole\Swoole\EventRegister;
use EasySwoole\EasySwoole\AbstractInterface\Event;
use EasySwoole\Http\Request;
use EasySwoole\Http\Response;

class EasySwooleEvent implements Event
{

    /**
     * 1.根据启动文件, 加载配置文件
     * 2.执行initialize方法
     * 3.目录初始化
     * 4.注册错误回调
     */
    public static function initialize()
    {
        // TODO: Implement initialize() method.
        //echo 'initialize'.PHP_EOL;
        date_default_timezone_set('Asia/Shanghai');
    }


    /**
     * 1.根据MAIN_SERVER配置, 创建出swoole_server对象
     * 2.为主服务注册默认事件, registerDefaultCallBack, onReceive、onRequest、onTask、onFinish、onPipeMessage、onWorkerStart
     * 3.调用全局事件的主服务创建逻辑, 也就是调用mainServerCreate
     */
    public static function mainServerCreate(EventRegister $register)
    {
        // TODO: Implement mainServerCreate() method.
        //echo 'mainServerCreate'.PHP_EOL;

        //ORM连接注册

    }

    public static function onRequest(Request $request, Response $response): bool
    {
        // TODO: Implement onRequest() method.
        //echo 'onRequest'.PHP_EOL;
        return true;
    }

    public static function afterRequest(Request $request, Response $response): void
    {
        // TODO: Implement afterAction() method.
        //echo 'afterRequest'.PHP_EOL;
    }
}